package com.lc202310;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * Description:
 *
 * @Create 2023/10/13 21:16
 * @Version 1.0
 */
public class SolutionError1488 {
    public static int[] avoidFlood(int[] rains) {
        List<Integer> full = new ArrayList<>();
        int empty = 0;
        for (int i = 0; i < rains.length; i++) {
            if (rains[i] > 0) {
                if (i == full.size()) {
                    full.add(rains[i]);
                    full.sort(Comparator.reverseOrder());
                    rains[i] = -1;
                    continue;
                }
                if (empty - rains[i] < 0) {
                    return new int[0];
                }
                empty -= rains[i];
                full.add(rains[i]);
                full.sort(Comparator.reverseOrder());
                rains[i] = -1;
                continue;
            }
            if (full.isEmpty()) {
                rains[i] = 1;
                continue;
            }
            rains[i] = full.get(0);
            empty += full.get(0);
            full.remove(0);
        }
        return rains;
    }

/*    public static int[] avoidFlood(int[] rains) {
        Set<Integer> set = new HashSet<>();
        int empty = 0;
        for (int i = 0; i < rains.length; i++) {
            if (rains[i] == 0) {
                if (empty == 0 && set.size() == 0) {
                    rains[i] = 1;
                }

            }
            set.add()

        }
    }*/

    public static void main(String[] args) {
        int[] arr = {1, 2, 0, 0, 2, 1};
        avoidFlood(arr);
        System.out.println("hello");
    }
}
